package com.jd.header.util;

import android.util.Log;

public class ILog {

    public static final String TAG = "ILog";
    private static boolean bEnableLog = true;

    public static String getRunInfo() {
        StringBuffer toStringBuffer = null;
        try {
            StackTraceElement traceElement = ((new Exception()).getStackTrace())[3];
            StackTraceElement traceElement2 = ((new Exception())
                    .getStackTrace())[4];
            toStringBuffer = new StringBuffer(""
                    + Thread.currentThread().getId()).append(" | ")
                    .append(traceElement.getFileName()).append(" | ")
                    .append(traceElement.getLineNumber()).append(" | ")
                    .append(traceElement2.getMethodName()).append(" -> ")
                    .append(traceElement.getMethodName()).append("()");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return toStringBuffer != null ? toStringBuffer.toString() : null;
    }

    public static String wrapLog(String msg) {
        return "[" + getRunInfo() + "] " + msg;
    }

    public static void i(String msg) {
        if (!bEnableLog) {
            return;
        }
        Log.i(TAG, wrapLog(msg));
    }

    public static void e(String msg) {
        if (!bEnableLog) {
            return;
        }
        Log.e(TAG, wrapLog(msg));
    }

    public static void e(String msg, Throwable tr) {
        if (!bEnableLog) {
            return;
        }
        Log.e(TAG, wrapLog(msg), tr);
    }

    public static void w(String msg) {
        if (!bEnableLog) {
            return;
        }
        Log.w(TAG, wrapLog(msg));
    }

    public static void w(String msg, Throwable tr) {
        if (!bEnableLog) {
            return;
        }
        Log.w(TAG, wrapLog(msg), tr);
    }

    public static void p(Throwable tr) {
        if (!bEnableLog) {
            return;
        }
        Log.w(TAG, tr);
    }

}
